package com.lebang.service.buss;

import com.lebang.entity.sys.Custom;
import com.lebang.example.CustomExample;
import com.lebang.mapper.buss.CustomMapper;
import com.lebang.model.Whether;
import com.lebangweb.response.Callback;
import com.lebangweb.response.JsonData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author hwq
 */
@Service
public class CustomService {
    @Autowired
    private CustomMapper customMapper;

    public JsonData insert(Custom po) {
        po.setHasDeleted(Whether.NO.getDbIndex());
        po.setModifyTime(new Date());
        po.setCreateTime(new Date());
        int init = customMapper.insertSelective(po);

        if (init > 0) {

            return Callback.success("200", "新增成功", null);
        } else {

            return Callback.fail("403", "新增失败", null);
        }
    }


    public JsonData update(Custom po) {
        po.setModifyTime(new Date());
        int init = customMapper.updateByPrimaryKeySelective(po);
        if (init > 0) {

            return Callback.success("200", "修改成功", null);
        } else {

            return Callback.fail("403", "修改失败", null);
        }
    }


    public Custom selectByPrimaryKey(Integer id) {
        return customMapper.selectByPrimaryKey(id);
    }

    public List<Custom> getAllCustomList() {
        return customMapper.getAllCustomList();
    }

    public String selectByCustomId(String customer) {
        return customMapper.selectByCustomId(customer);
    }

    public Object count(CustomExample example) {
        return customMapper.countByExample(example);
    }

    public List<Custom> selectAll(CustomExample example) {
        return customMapper.selectByExample(example);
    }

    public void deletedData(Integer ids) {
        customMapper.deleteByPrimaryKey(ids);
    }
}
